package geowiki.vis;

import processing.core.PApplet;
import processing.core.PVector;

public class GumConnections extends PApplet {

	GumConnection gumConnection;

	GumConnection gumConnectionStatic;

	boolean debug = false;

	public void setup() {
		size(800, 600);
		smooth();

		gumConnection = new GumConnection(this, new PVector(200, 200), new PVector(500, 200));
		gumConnection.col = color(200, 20, 10, 100);

		gumConnectionStatic = new GumConnection(this, new PVector(600, 400), new PVector(650, 550), 30, 20);
		gumConnectionStatic.maxDistance = 150;
		gumConnectionStatic.col = color(0, 0, 200, 60);
	}

	public void draw() {
		background(255);
		stroke(0);

		gumConnection.draw();
		if (debug) {
			gumConnection.drawDebug();
		}

		gumConnectionStatic.draw();
	}

	public void mouseDragged() {
		if (mouseButton == LEFT) {
			gumConnection.setEndPoint(mouseX, mouseY);
		} else {
			float d = dist(pmouseX, pmouseY, mouseX, mouseY);
			if (pmouseX < mouseX) {
				gumConnection.addRadiusSP(-d);
			} else {
				gumConnection.addRadiusSP(d);
			}
		}
	}

	public void keyPressed() {
		if (key == 'd') {
			debug = !debug;
		}
	}

}
